package com.jy.wms.controller;

import com.github.pagehelper.Page;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.UUIDUtils;
import com.jy.wms.common.base.BaseController;
import com.jy.wms.common.base.JsonResult;
import com.jy.wms.common.base.ResultPage;
import com.jy.wms.pojo.WmsPackingDetailed;
import com.jy.wms.service.WmsPackingDetailedService;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: WmsPackingDetailedController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author JaneLiu
 * @Date Wed Sep 06 17:40:56 CST 2017
 */
@Controller
@RequestMapping("/wmspackingdetailed")
public class WmsPackingDetailedController extends BaseController<WmsPackingDetailedService,WmsPackingDetailed> {

    @RequestMapping("/toWmsPackingDetailed")
    public String toWmsPackingDetailed() {
        return "wmspackingdetailed/wmspackingdetailed";
    }

   /* @RequestMapping(value = {"list", ""})
    public @ResponseBody
    ResultPage<WmsPackingDetailed> getWmsPackingDetailed(@RequestBody WmsPackingDetailed entity, HttpSession session) {
        Page<WmsPackingDetailed> list= baseService.baseSelectPage(entity);
            return renderPage(list);
    }

    @RequestMapping(value = "delete")
    public @ResponseBody
    JsonResult deleteWmsPackingDetailed(@RequestBody List<String> ids) {
        Integer flag=baseService.baseDeleteBathPrimaryKeys(ids);
        return renderSuccess("删除成功");
    }

    @RequestMapping(value = "add")
    public @ResponseBody
    JsonResult addWmsPackingDetailed(@RequestBody WmsPackingDetailed entity) {
        entity.setId(UUIDUtils.uuid());
        baseService.baseInsert(entity);
        return renderSuccess("删除成功");
    }

    @RequestMapping(value = "getWmsPackingDetailed/{id}")
    public @ResponseBody
    WmsPackingDetailed getWmsPackingDetailedById(@PathVariable("id") String id) {
        WmsPackingDetailed entity=baseService.baseSelectByPrimaryKey(id);
        return entity;
    }
    @RequestMapping(value = "edit")
    public @ResponseBody
    JsonResult editWmsPackingDetailed(@RequestBody WmsPackingDetailed entity) {
        Integer flag=baseService.baseUpdateByPrimaryKeySelective(entity);
        return renderSuccess("删除成功");
    }*/
    /**
     * 静姐的方法
     * 根据包装ID查询包装明细
     * @return
     */
    @GetMapping(value = "/getWmsPackingDetailedByBzid/{bzid}")
    @ApiOperation(value = "包装管理 查看单个包装的包装明细",response = JSONObject.class, notes = "GET查看单个包装的包装明细")
    public @ResponseBody
    JSONObject getWmsPackingBySshzid(@PathVariable("bzid") String bzid) {
        JSONObject json = getJSONObject();
        List<WmsPackingDetailed> entity=  new ArrayList<WmsPackingDetailed>();
        SetStatus setStatus = new SetStatus();
        try {
            entity = baseService.baseSelectByBzid(bzid);
            json = SetStatus.setSearchType(JSONArray.fromObject(entity).toString(),(int) entity.size());
        } catch (Exception e) {
            logger.error(e.getMessage());
            e.printStackTrace();
            json = SetStatus.setFunctionType(1,"error","包装管理","查看单个货主的未绑定货主包装失败","");
        }
        return json;
    }
}
